package com.sinothk.gpserver.modules.system.service.impl;

import com.sinothk.gpserver.modules.system.entity.UserEntity;
import com.sinothk.gpserver.modules.system.entity.UserRoleEntity;
import com.sinothk.gpserver.modules.system.mapper.UserMapper;
import com.sinothk.gpserver.modules.system.mapper.UserRoleMapper;
import com.sinothk.gpserver.modules.system.service.IUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sinothk.server.support.entity.PageData;
import com.sinothk.server.support.entity.PageVo;

import javax.annotation.Resource;

/**
 * <p>
 * 用户角色功能 服务实现类
 * </p>
 *
 * @author Liang Y.t.
 * @since 2021-08-27
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRoleEntity> implements IUserRoleService {

    @Resource
    private UserRoleMapper userRoleMapper;

    /**
     * 查询分页数据
     *
     * @param pageVo 分页参数
     * @return PageData
     */
    @Override
    public PageData<UserRoleEntity> page(PageVo<UserRoleEntity> pageVo) {
        Page<UserRoleEntity> page = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        Page<UserRoleEntity> userIPage = userRoleMapper.selectPage(page, null);

        // 组装
        PageData<UserRoleEntity> rspPageData = new PageData<>();
        rspPageData.setPageNum(userIPage.getCurrent());
        rspPageData.setPageSize(userIPage.getSize());
        rspPageData.setCurrent(userIPage.getCurrent());
        rspPageData.setTotal(userIPage.getTotal());
        rspPageData.setData(userIPage.getRecords());

        return rspPageData;
    }

}
